<?php

class Application_Model_ReportsTbl extends Zend_Db_Table_Abstract{
	protected $_name = 'reports';
	
	
	function getOffensiveReports($user_fk)
    {
    	
    	//date, attacker_id, defender_id, nr_of_raids, result, coins, a_xp, d_xp, a_units_lost, a_power_lost, d_units_lost, d_power_lost, attacker_damage, defender_damage, a_lvl1, a_lvl2, a_lvl3, a_lvl4, a_lvl5, a_lvl6, d_lvl1, d_lvl2, d_lvl3, d_lvl4, d_lvl5, d_lvl6
   		 $select = $this->_db->select()
                            ->from(array('r' => $this->_name), array('date',
                            							'defender_id',
                            							'sum(nr_of_raids)',
                            							'result',
                            							'sum(coins)',
                            							'sum(a_xp)',
                            							'sum(a_units_lost)',
                            							'sum(a_power_lost)',
                            							'sum(d_units_lost)',
                            							'sum(d_power_lost)',
                            							'sum(attacker_damage)',
                            							'sum(defender_damage)',
                            							'sum(a_lvl1)',
                            							'sum(a_lvl2)',
                            							'sum(a_lvl3)',
                            							'sum(a_lvl4)',
                            							'sum(a_lvl5)',
                            							'sum(a_lvl6)',
                            							'sum(d_lvl1)',
                            							'sum(d_lvl2)',
                            							'sum(d_lvl3)',
                            							'sum(d_lvl4)',
                            							'sum(d_lvl5)',
                            							'sum(d_lvl6)'))
                            ->where('r.attacker_id=?',$user_fk)
                            ->order('r.date ASC')
                            ->group('r.attacker_id')
                            ->group('r.result');
                            
        $result = $this->getAdapter()->fetchAll($select);
        
    	return $result;
 	}
 	
 	
	function getDefensiveReports($user_fk)
    {
    	
    	//date, attacker_id, defender_id, nr_of_raids, result, coins, a_xp, d_xp, a_units_lost, a_power_lost, d_units_lost, d_power_lost, attacker_damage, defender_damage, a_lvl1, a_lvl2, a_lvl3, a_lvl4, a_lvl5, a_lvl6, d_lvl1, d_lvl2, d_lvl3, d_lvl4, d_lvl5, d_lvl6
   		 $select = $this->_db->select()
                             ->from(array('r' => $this->_name), array('date',
                            							'attacker_id',
                            							'sum(nr_of_raids)',
                            							'result',
                            							'sum(coins)',
                            							'sum(a_xp)',
                            							'sum(a_units_lost)',
                            							'sum(a_power_lost)',
                            							'sum(d_units_lost)',
                            							'sum(d_power_lost)',
                            							'sum(attacker_damage)',
                            							'sum(defender_damage)',
                            							'sum(a_lvl1)',
                            							'sum(a_lvl2)',
                            							'sum(a_lvl3)',
                            							'sum(a_lvl4)',
                            							'sum(a_lvl5)',
                            							'sum(a_lvl6)',
                            							'sum(d_lvl1)',
                            							'sum(d_lvl2)',
                            							'sum(d_lvl3)',
                            							'sum(d_lvl4)',
                            							'sum(d_lvl5)',
                            							'sum(d_lvl6)'))
                            ->where('r.defender_id=?',$user_fk)
                            ->order('r.date ASC')
                            ->group('r.defender_id')
                            ->group('r.result');
                            
        $result = $this->getAdapter()->fetchAll($select);
        
    	return $result;
 	}
	
}




